#include "stdafx.h"
#include "SceneManager.h"
#include "GamePlayer.h"
#include "FPSGameRule.h"
#include "FootBallGameRule.h"

CSceneManager::CSceneManager()
{
	mpGameMode = new CGameMode;
}

CSceneManager::~CSceneManager()
{

}

void CSceneManager::initialise(int gameMode)
{
	switch (gameMode)
	{
	case 0:
		mpGameMode->setGameRule(new CFPSGameRule());
		break;
	case 1:
		mpGameMode->setGameRule(new CFootBallGameRule());
		break;
	default:
		mpGameMode->setGameRule(new CGameRule());
		break;
	}
}

void CSceneManager::destory()
{
	SafeDelete(mpGameMode);
}

void CSceneManager::addEntity(mini::CEntity* pEntity)
{
	auto item = std::find(mEntities.begin(), mEntities.end(), pEntity);
	if (item != mEntities.end())
	{
		if (pEntity->getEntityType() == mini::EntityType::Actor)
		{
			CGamePlayer* pGamePlayer = dynamic_cast<CGamePlayer*>(pEntity);
			pGamePlayer->setGameRule(mpGameMode->getGameRule());
		}
		mEntities.push_back(pEntity);
	}
}

void CSceneManager::removeEntity(mini::CEntity* pEntity)
{
	auto item = std::find(mEntities.begin(), mEntities.end(), pEntity);
	if (item != mEntities.end())
	{
		mEntities.erase(item);
	}
}

void CSceneManager::run()
{
	mTaskManager.tick();
	mBuffManager.tick();
}
